#ifndef HTTPGET_H
#define HTTPGET_H

#include <QObject>
class QUrl;
class QString;
class QFile;
class QNetworkReply;
class QNetworkAccessManager;

class HttpGet : public QObject
{
    Q_OBJECT
public:
    explicit HttpGet(const QUrl &url, const QString &filename, QObject *parent = 0);
    inline QString &getFileName(void) {return name;}
    
signals:
    void finished(HttpGet *self, bool error);
    void retryLater(HttpGet *self);
    void progressChanged(HttpGet *self, int percent);

private:
    void start(const QUrl &url);
    QFile *file;
    QString name;
    QNetworkReply *reply;
    int prev_percentage;
    int retry_times;
    qint64 last_finished;
    static QNetworkAccessManager *manager;
    
private slots:
    void onFinished(void);
    void onReadyRead(void);
    void onProgressChanged(qint64 received, qint64 total);
    void retry(void);
};

#endif // HTTPGET_H
